home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / msdos / cc / function.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  2KB  |  84 lines

  1. #include <string.h>
  2. #include <dos.h>
  3. #include "function.h"
  4.  
  5. static char buffer[128];
  6.  
  7. /*  ファイルの作成時刻を取得する  */
  8. unsigned long FileTime( char *FileName )
  9. {
  10.     int fh;
  11.     unsigned int date,time;
  12.  
  13.     if( _dos_open( FileName,0x00,&fh ) )   return( 0 );
  14.     if( _dos_getftime( fh,&date,&time ) )  return( 0 );
  15.     _dos_close( fh );
  16.     return( (date << 16) + time );
  17. }
  18.  
  19. /*  カレントまたはリストのディレクトリからファイルを探す  */
  20. char *FindFile( char *FileName,char *PathList )
  21. {
  22.     int  fh;
  23.     char *path,*p;
  24.  
  25.     if( _dos_open( FileName,0x00,&fh ) == 0 ) {
  26.         _dos_close( fh );
  27.         return( FileName );
  28.     }
  29.  
  30.     path = PathList;
  31.     while( *path == ' ' )  path++;
  32.     while( path && *path && *path != ';' ) {
  33.         p = buffer;
  34.         while( *path && *path != ';' )  *p++ = *path++;
  35.         if( *path == ';' )   path++;
  36.         if( *(p-1) != '\\' )  *p++ = '\\';
  37.         strcpy( p,FileName );
  38.         if( _dos_open( buffer,0x00,&fh ) == 0 ) {
  39.             _dos_close( fh );
  40.             return( buffer );
  41.         }
  42.     }
  43.     return( NULL );
  44. }
  45.  
  46. /*  パス名とファイル名を結合する  */
  47. char *JoinPath( char *path,char *FileName )
  48. {
  49.     char *p;
  50.  
  51.     p = buffer;
  52.     if( *path ) {
  53.         while( *path )  *p++ = *path++;
  54.         if( *(p-1) != '\\' )  *p++ = '\\';
  55.     }
  56.     strcpy( p,FileName );
  57.     return( buffer );
  58. }
  59.  
  60. /*  パスからファイルの拡張子を探す  */
  61. char *SearchExt( char *path )
  62. {
  63.     char *p;
  64.  
  65.     if( p = strrchr( path,'\\' ) )  path = p;
  66.     else                            p = path;
  67.     if( p = strrchr( path,'.' )  )  path = p;
  68.     else                            while( *path )  path++;
  69.     return( path );
  70. }
  71.  
  72. /*  パスからファイル名を探す  */
  73. char *SearchFile( char *path )
  74. {
  75.     char *p;
  76.  
  77.     if( p = strchr( path,':' )   )  path = p++;
  78.     else                            p = path;
  79.     if( p = strrchr( path,'\\' ) )  path = p++;
  80.     else                            p = path;
  81.     return( path );
  82. }
  83.  
  84.